import 'package:aero_frisbee/app/model/cache_bind_model/cache_bind_model.dart';
import 'package:aero_frisbee/gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'local_post_model.freezed.dart';
part 'local_post_model.g.dart';

@freezed
class LocalPostModel with _$LocalPostModel {
  factory LocalPostModel({
    int? uid,
    String? author,
    int? followeds,
    @JsonKey(name: 'post_cover') String? postCover,
    @JsonKey(name: 'post_img') String? postImg,
    String? desc,
    String? title,
    @Default(false) bool isLike,
    int? type,
    CacheBindModel? cacheBind,
  }) = _LocalPostModel;

  factory LocalPostModel.fromJson(Map<String, dynamic> json) =>
      _$LocalPostModelFromJson(json);
}

extension LocalPostModelX on LocalPostModel {
  Image get markImg {
    if (type == 0) {
      return Assets.icons.iconHotCornerMark.image(width: 38);
    } else if (type == 1) {
      return Assets.icons.iconLikeCornerMark.image(width: 38);
    } else if (type == 2) {
      return Assets.icons.iconNewCornerMark.image(width: 38);
    } else {
      return Assets.icons.iconNewCornerMark.image(width: 38);
    }
  }

  List<String> get imgs {
    if (postImg != null &&
        postImg!.isNotEmpty &&
        postCover != null &&
        postCover!.isNotEmpty) {
      return [postCover!, ...postImg!.split(',')];
    } else if (postCover != null && postCover!.isEmpty) {
      return [postCover!];
    } else if (postImg != null && postImg!.isNotEmpty) {
      return [...postImg!.split(',')];
    } else {
      return [];
    }
  }
}
